package CPU工作原理作业;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-12-21
 * Time: 19:47
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        Threads threads=new Threads();

        Thread thread1=new Thread(() ->{
            for (int i = 0; i < 10000; i++) {
                threads.add();
            }
        });

        Thread thread2=new Thread(() ->{
            for (int i = 0; i < 10000; i++) {
                threads.add();
            }
        });

        thread1.start();
        thread2.start();
        Thread.sleep(5000);
        System.out.println(threads.s);
    }
}
class Threads{
    int s=0;
    synchronized void add(){
        s++;
    }
    int result(){
        return this.s;
    }
}